package com.anyext.storage.mapping.impl;

import java.util.Map;

import org.springframework.beans.factory.InitializingBean;

import com.anyext.storage.StorageContext;
import com.anyext.storage.group.Group;
import com.anyext.storage.mapping.Attribute;
import com.anyext.storage.mapping.Business;
import com.anyext.storage.mapping.PrimaryKey;
import com.anyext.storage.router.Router;

public class BusinessImpl implements Business, InitializingBean {

	private String					identity;

	private Class<?>				beanClass;

	private String					table;

	private Group					group;

	private Router					router;

	private PrimaryKey				primaryKey;

	private Map<String, Attribute>	attributes;

	@Override
	public String getIdentity() {
		return identity;
	}

	public void setIdentity(String identity) {
		this.identity = identity;
	}

	@Override
	public Class<?> getBeanClass() {
		return beanClass;
	}

	public void setBeanClass(Class<?> beanClass) {
		this.beanClass = beanClass;
	}

	@Override
	public String getTable() {
		return table;
	}

	public void setTable(String table) {
		this.table = table;
	}

	@Override
	public Group getGroup() {
		return group;
	}

	public void setGroup(Group group) {
		this.group = group;
	}

	@Override
	public Router getRouter() {
		return router;
	}

	public void setRouter(Router router) {
		this.router = router;
	}

	@Override
	public PrimaryKey getPrimaryKey() {
		return primaryKey;
	}

	public void setPrimaryKey(PrimaryKey primaryKey) {
		this.primaryKey = primaryKey;
	}

	@Override
	public Map<String, Attribute> getAttributes() {
		return attributes;
	}

	@Override
	public Attribute getAttribute(String name) {
		return attributes.get(name);
	}

	public void setAttribute(String name, Attribute attribute) {
		this.attributes.put(name, attribute);
	}

	public void setAttributes(Map<String, Attribute> attributes) {
		this.attributes = attributes;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		StorageContext.addBusinessName(this.identity);
	}

}
